Extracting Strings
- Extracting the first character of a string
var firstChar = cityToCheck.slice(0, 1);
or
var firstChar = cityToCheck.charAt(0);
- Extracting the last character of a string
var lastChar = cityToCheck.charAt(cityToCheck.length -1);
- Extracts "sto" from the String equal to Boston
var someChars = cityToCheck.slice(2, 5);
- Extracts all characters after the 3rd character in Boston making someChars = "ston"
var someChars = cityToCheck.slice(2);